#include "gameobjectpool.h"


GameObjectPool*GameObjectPool::instance=nullptr;
GameObjectPool::GameObjectPool(QObject *parent)
    : QObject{parent}
{

}

void GameObjectPool::Init()
{
    //预先生产对象
    for(int i=0;i<20;i++)
    {
        Enemyfalling* enemyfalling  =new Enemyfalling();
        mFallingPool.append(enemyfalling);
    }
}

GameObject *GameObjectPool::GetGameObject(int _objectType)
{
    switch(_objectType)
    {
    case GameObject::QT_Enemyfalling://掉落物
    {Enemyfalling*enemyfalling=mFallingPool.first();
        mFallingPool.pop_front();

        return enemyfalling;
    }
    }
}

void GameObjectPool::RecoveryGameObject(GameObject *_object)
{
    switch (_object->GetType())
    {
    case GameObject::QT_Enemyfalling:
    {
        mFallingPool.append((Enemyfalling*)_object);
        break;
    }
    }

}

void GameObjectPool::Clear()
{
    //清楚掉落物容器
    for(auto pEnemyfalling:mFallingPool)
    {
        delete pEnemyfalling;
    }
}
